package com.jk.dmconsumer.controller;

import com.jk.dmcommon.wlentity.*;
import com.jk.dmconsumer.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * 文件名称:HomeController
 *
 * @Description //TODO
 * @Date 2021/9/8 18:17
 * 作者 王乐
 * Copyright (c) 2021,  All Rights Reserved.</pre>
 */
@RestController
public class HomeController {
    @Autowired
    private HomeService homeService;
    @Autowired
    private JumpController jumpController;
    /**
    *  @方法描述 (首页各类商品查询)
     * @Author 王乐
     * @Description //TODO 
     * @Date  2021/9/8 18:23
     * @Param [goods]
     * @return java.util.List<com.jk.dmcommon.wlentity.GoodsDetailEntity>
     **/
    @RequestMapping("/home/getHomeGoods")
    public String getHomeGoods(GoodsDetailEntity goods){
        List<GoodsDetailEntity> list= homeService.getHomeGoods(goods);
        if(list.size()==0){
            return "";
        }
        GoodsDetailEntity[] arr =  list.toArray(new GoodsDetailEntity[0]);
       // GoodsSessionEntity[] arrgs1=arr[0].getGoodsSessionEntityList().toArray(new GoodsSessionEntity[0]);
       // GoodsLeaveEntity[] arrgl1=arrgs1[0].getGoodsLeaveList().toArray(new GoodsLeaveEntity[0]);
        String str = "";
      //  str+= "<div class=\"box\">\n" +
              str+=  "   <!--第一个大图-->\n" +
                "   <a href=\"/lwl?goodsId="+arr[0].getGoodsId()+"\" class=\"box-left\" target=\"_blank\"\n" +
                "      data-spm=\"ditem_0\" id=\"dm-content-1-a0\">\n" +
                "       <img class=\"box-left__bg\" src=\""+arr[0].getGoodsImg()+"\" id=\"dm-content-1-img0\">\n" +
                "       <div class=\"box-left__info\">\n" +
                "           <div class=\"title\" id=\"dm-content-1-div0-1\">"+arr[0].getGoodsName()+"</div>\n" +
                "           <div class=\"details\" id=\"dm-content-1-div0-2\">¥"+arr[0].getMinPrice()+"<span>起</span></div>\n" +
                "       </div>\n" +
                "   </a>\n" +
                "   <div class=\"box-right\">";
                for(int i=1;i< arr.length;i++){
                 //   GoodsSessionEntity[] arrgs=arr[i].getGoodsSessionEntityList().toArray(new GoodsSessionEntity[0]);
                //    GoodsLeaveEntity[] arrgl=arrgs[0].getGoodsLeaveList().toArray(new GoodsLeaveEntity[0]);

             //  str+="   <div class=\"box-right\">\n" +
              str+=  "       <!--小图1-->\n" +
                "       <a href=\"/lwl?goodsId="+ arr[i].getGoodsId()+"\" class=\"box-right__item\" data-spm=\"ditem_"+i+"\"\n" +
                "          target=\"_blank\" >\n" +
                "           <div class=\"itemimg\">\n" +
                "               <img src=\""+arr[i].getGoodsImg()+"\" >\n" +
                "           </div>\n" +
                "           <div class=\"iteminfo\">\n" +
                "               <div class=\"title\" title=\""+arr[i].getGoodsName()+"\" >"+arr[i].getGoodsName()+"</div>\n" +
                "               <div class=\"venue\" >"+arr[i].getGoodsAdress()+"</div>\n" +
                "               <div class=\"showtime\" >"+arr[i].getGoodsStartTime()+"</div>\n" +
                "               <div class=\"showtime\"></div>\n" +
                "               <div class=\"price\" >¥"+arr[0].getMinPrice()+"<span>起</span></div>\n" +
                "           </div>\n" +
                "       </a>\n";
                }
                str+="</div>";
        return str;
      //  return homeService.getHomeGoods(goods);
    }
    /**
    *  @方法描述 (轮播图查询)
     * @Author 王乐
     * @Description //TODO 
     * @Date  2021/9/9 15:47
     * @Param []
     * @return java.util.List<com.jk.dmcommon.wlentity.SwiperEntity>
     **/
    @RequestMapping("home/getSwiper")
    public List<SwiperEntity> getSwiper(){
        return homeService.getSwiper();
    }
    /**
    *  @方法描述 (获取城市)
     * @Author 王乐
     * @Description //TODO 
     * @Date  2021/9/10 9:56
     * @Param []
     * @return java.lang.String
     **/
    @RequestMapping("home/getCity")
    public String getCity(){
        return homeService.getCity();
    }
    /**
    *  @方法描述 (获取登录信息)
     * @Author 王乐
     * @Description //TODO 
     * @Date  2021/9/13 6:49
     * @Param []
     * @return java.util.HashMap<java.lang.String,java.lang.Object>
     **/
    @RequestMapping("home/getLoginInfo")
    public HashMap<String,Object> getLoginInfo(){
        return homeService.getLoginInfo();
    }

    /**
     * 热门城市回显
     * @return
     */
    @RequestMapping("home/hotCity")
    public String hotCity(){
        return homeService.hotCity();
    }

    /**
     *  选中替换
     * @return
     */
    @RequestMapping("home/obtainCity")
    public String obtainCity(Integer cityid){
        return homeService.obtainCity(cityid);
    }
    /**
    *  @方法描述 (退出登录)
     * @Author 王乐
     * @Description //TODO 
     * @Date  2021/9/14 1:22
     * @Param []
     * @return void
     **/
    @RequestMapping("home/logout")
    public void logout(){
        homeService.logout();
        //跳首页
        //ModelAndView home = new ModelAndView("home");
      //  return home;
    }
}
